﻿using System;
using Client.SearchServiceReference;
using Util;

namespace Client
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Usage: {0} <flights search server URI>", AppDomain.CurrentDomain.FriendlyName);
                return;
            }

            var uri = args[0];
            if (!uri.StartsWith("http://"))
            {
                uri = "http://" + uri;
            }

            try
            {
                using (var connection = new WebConnection<ISearchService>(uri))
                {
                    Console.WriteLine("Client is running");
                    Console.WriteLine("Available commands: search, exit");

                    var ce = new CommandExecuter(connection.Channel);
                    ce.ExecuteUserCommands();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error occured: {0}, exiting", e.Message);
            }
        }
    }
}
